#include "ApproxSjf.h"
extern int N;
ApproxSjf::ApproxSjf(vector<OSThread*>* threads, int quanta) :
	OSScheduler(*threads), quanta(quanta), lastThread(0),avgQuanta(N,quanta)
{
}

//bla bla bla

ApproxSjf::~ApproxSjf()
{
}

void ApproxSjf:: runSomeThread() {

	int next = (lastThread == (N-1)) ? 1 : (lastThread + 1);

	int used = giveQuanta(next, avgQuanta[next]);

	avgQuanta[next] = (avgQuanta[next] + used)/2 == 0 ? 1 : (avgQuanta[next] + used)/2;

	lastThread=next;

}